package com.hanhai.zrb.backend.web.controller;

import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.github.pagehelper.PageInfo;
import com.hanhai.common.util.DateUtil;
import com.hanhai.common.web.controller.BaseController;
import com.hanhai.zrb.api.biz.service.UserBlacklistService;
import com.hanhai.zrb.model.user.UserBlacklist;
@Controller
@RequestMapping("userblacklist")
public class UserBlacklistController extends BaseController {

	@Resource
	private UserBlacklistService userBlacklistService;
	
	@RequestMapping("index")
	public String index(){
		return "userblacklist/index";
	}
	
	@RequestMapping("listNotInBlacklistPage")
	public String listNotInBlacklistPage(){
		return "userblacklist/listNotInBlacklistPage";
	}
	@RequestMapping("listPage")
	public void listPage(Integer page, Integer rows, HttpServletResponse response){
	
		PageInfo pageInfo=userBlacklistService.listPage(page, rows);

		super.jsonPage(response, pageInfo);
	}
	
	@RequestMapping("doadd")
	public void doAdd(UserBlacklist blacklist, HttpServletResponse response){
		if(blacklist.getUserId() == null){
			super.fail(response);
			return;
		}
		if(blacklist.getExpireTime()==null){
			blacklist.setExpireTime(DateUtil.addDay(new Date(), 7));
		}
		userBlacklistService.add(blacklist);
		super.success(response);
	}
	
	@RequestMapping("doupdate")
	public void doUpdate(UserBlacklist blacklist, HttpServletResponse response){
		userBlacklistService.update(blacklist);
		super.success(response);
	}
	
	@RequestMapping("dodelete")
	public void doDelete(UserBlacklist blacklist, HttpServletResponse response){
		userBlacklistService.delete(blacklist.getId());
		super.success(response);
	}
}
